package main

import (
	"encoding/json"

	"jlpay-sdk-go/pkg/jlpay/demo"
	"jlpay-sdk-go/pkg/jlpay/models/openmerch/bill"
	billservice "jlpay-sdk-go/pkg/jlpay/services/openmerch/bill"
	"jlpay-sdk-go/pkg/jlpay/utils"
)

// 构建结算账单查询请求
func buildSettleBillQueryRequest() *bill.SettleBillQueryRequest {
	request := bill.NewSettleBillQueryRequest()

	// 设置请求参数
	request.SetMerchNo("849584358120018")
	request.SetStartBusiDate("2024-07-01")
	request.SetEndBusiDate("2024-07-02")
	request.SetStartSettleDate("2024-07-01")
	request.SetEndSettleDate("2024-07-02")
	request.SetPayStatus("1")

	return request
}

// 结算账单查询示例
func settleBillQueryDemo(billService *billservice.BillService) {
	utils.Info("开始执行结算账单查询示例")

	// 创建结算账单查询请求
	request := buildSettleBillQueryRequest()

	// 序列化请求数据并打印
	requestMap, _ := request.ToMap()
	requestJSON, _ := json.Marshal(requestMap)
	utils.Debugf("结算账单查询请求数据: %s", string(requestJSON))

	// 发送请求
	response, err := billService.SettleBillQuery(request)
	if err != nil {
		utils.Errorf("结算账单查询请求失败: %v", err)
		return
	}

	// 处理响应 - 使用BaseResponse接口的HandleResponse方法
	response.HandleResponse("结算账单查询")

	utils.Info("结算账单查询示例执行完毕")
}

func main() {
	// 设置日志级别为info，显示详细的调试信息
	utils.SetLogLevel("info")

	utils.Info("=============================")
	utils.Info("===== 结算账单查询示例 开始 =====")
	utils.Info("=============================")

	// 创建配置对象和账单服务
	config := demo.CreateDemoConfig()
	billService := billservice.NewBillService(config)

	settleBillQueryDemo(billService)

	utils.Info("=============================")
	utils.Info("===== 结算账单查询示例执行完毕 =====")
	utils.Info("=============================")
}
